package org.ogv.usada.views;

import org.ogv.OGV;
import org.ogv.usada.models.GP;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.BitmapFontCache;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Rectangle;

public class GameHUD {

	private TextureRegion 		_coin;
	private BitmapFontCache		_font;
	private Clock				_clock;
	private Sprite 				_menu;
	private Sprite				_recipe;
	private Rectangle			_rect;
	
	public void init() {
		_rect = new Rectangle();
		
		_coin = OGV.asset.getTextureRegion(GP.$().RES_TEXR_COIN);
		_font = new BitmapFontCache(OGV.asset.get(GP.$().RES_FONT_PRINTCLEARLY, BitmapFont.class));
		_font.setColor(GP.$().GAME_COIN_FONTCOLOR);
		_clock= new Clock();
		_clock.setPosition((GP.$().GAME_WIDTH - _clock.getWidth() - 12), (GP.$().GAME_HEIGHT - _clock.getHeight()) - 11);
		_menu = new Sprite(OGV.asset.getTextureRegion(GP.$().RES_TEXR_MENU));
		_menu.setPosition(_clock.getX() - _menu.getWidth() - 20, (GP.$().GAME_HEIGHT - _menu.getHeight()) - 11);
		_recipe = new Sprite(OGV.asset.getTextureRegion(GP.$().RES_TEXR_RECIPE));
		_recipe.setPosition(_menu.getX() - _recipe.getWidth() - 20, (GP.$().GAME_HEIGHT - _recipe.getHeight()) - 11);
	}
	
	public boolean isMenuClicked(float touchX, float touchY) {
		_rect.set(_menu.getX(), _menu.getY(), _menu.getWidth(), _menu.getHeight());
		return _rect.contains(touchX, touchY);
	}

	public boolean isRecipeClicked(float touchX, float touchY) {
		_rect.set(_recipe.getX(), _recipe.getY(), _recipe.getWidth(), _recipe.getHeight());
		return _rect.contains(touchX, touchY);
	}
	
	public void draw(SpriteBatch sb, int curScore, float curTimeNormalized) {
		//draw coin
		sb.draw(_coin, 12, GP.$().GAME_HEIGHT - _coin.getRegionHeight() - 11);
		_font.setText(
			curScore + "", 
			(_coin.getRegionWidth() + 12 + 5), 
			(GP.$().GAME_HEIGHT - _coin.getRegionHeight() + ((_coin.getRegionHeight()) >> 1) + 11)
		);
		_font.draw(sb);
		
		//draw clock
		_clock.progress = curTimeNormalized;
		_clock.draw(sb);
		
		//draw menu
		_menu.draw(sb);
		_recipe.draw(sb);
	}
}
